#ifndef Define_LcBagging
#define Define_LcBagging

#include <cstring>
#include <opencv2/opencv.hpp>
#include <opencv2/flann/config.h>

#include <opencv2/legacy/legacy.hpp>		// EM
#include <opencv2/contrib/contrib.hpp>		// colormap
#include <opencv2/nonfree/nonfree.hpp>		// SIFT

#include "LcBasic.h"
#include "Classifier.h"
#include "FeatureComputer.h"
#include "VideoRead.h"

using namespace std;
using namespace cv;


class LcBagging : public LcClassifier
{
public:

	int veb;

	LcBagging();

	void train( LcVideoRead & reader );

	LcValidator predict(Mat & feature, Mat & res, Mat & label);
	LcValidator predict( LcVideoRead & test_reader );

	void predict( LcVideoRead & test_reader , vector< LcValidator > & validator_array);
	void predict(Mat & feature, Mat & res, Mat & label, vector< LcValidator > & validator_array);
	//these two interface is to incrementally test the preformance

	void save( string filename_prefix );
	void load( string filename_prefix );

	void setClassifier( LcClassifier* n_classifier);
	void setReader( LcVideoRead * n_reader );
	
	void setFeatureCode( const char * n_code_string );

	int n_classifier;

	int instance_limit;

	float downsample_rate;
	int feature_dim;

private:

	void initTrain();
	void initClassifier();

	void computeRate(); //compute the down sample rate.

	void append( Mat & feat    , Mat & lab,
				 Mat & feat_frm, Mat & lab_frm,
				 int & flag );

	vector< LcClassifier* > h;

	LcClassifier * classifier_prototype;
	LcFeatureExtractor * my_extractor;
	void setExtractor( LcFeatureExtractor * n_extractor );

	LcVideoRead * my_reader;
	const char * feature_code_string;
};



#endif

